package com.example.controller.message;

import com.example.controller.message.request.CreateMessageRequest;
import com.example.entity.Message;
import com.example.service.MessageService;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class MessageController {
    private final MessageService messageService;

    @GetMapping("/message")
    public List<Message> getMessages() {
        return messageService.getAll();
    }

    @PostMapping("/message")
    public Message addMessage(@RequestBody CreateMessageRequest request) {
        return messageService.createMessage(request.getMessage());
    }


}
